package com.zygh.interactiveplatform.module.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.interactiveplatform.common.constant.EmployeeResponseCodeConst;
import com.zygh.interactiveplatform.common.domain.ResponseDTO;
import com.zygh.interactiveplatform.module.entity.BlockManagement;
import com.zygh.interactiveplatform.module.entity.BlockManagement;
import com.zygh.interactiveplatform.module.mapper.BlockManagementMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zygh.interactiveplatform.module.mapper.BlockManagementMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lee
 * @since 2021-02-03
 */
@Service
public class BlockManagementService extends ServiceImpl<BlockManagementMapper, BlockManagement>{
    @Resource
    private BlockManagementMapper blockManagementMapper;

    public ResponseDTO addBlockManagement(BlockManagement blockManagement) {
        int insert = blockManagementMapper.insert(blockManagement);
        if (insert > 0) {
            return ResponseDTO.succ();
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.ADD_EXIST);
    }

    public ResponseDTO updateBlockManagement(BlockManagement blockManagement) {
        int insert = blockManagementMapper.updateById(blockManagement);
        if (insert > 0) {
            return ResponseDTO.succ();
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.UPDATE_EXIST);
    }
    public ResponseDTO deleteBlockManagement(Integer id) {
        int insert = blockManagementMapper.deleteById(id);
        if (insert > 0) {
            return ResponseDTO.succ();
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.DELETE_EXIST);
    }
    public ResponseDTO findBlockManagementAll(Integer current, Integer size) {
        PageHelper.startPage(current, size);
        List<BlockManagement> blockManagements = blockManagementMapper.selectList(null);
        if (blockManagements != null) {
            PageInfo<BlockManagement> pageInfo = new PageInfo<>(blockManagements);
            return ResponseDTO.succData(pageInfo);
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.EMPTY_INFORMATION_ERROR);
    }
}
